/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rockville.ufone;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;

import org.apache.log4j.Logger;

/**
 * 
 * @author M Bilal
 */
public class CricLiveScoreHandler implements Runnable {

    private static final Logger log = Logger.getLogger(CricLiveScoreHandler.class);
    private static ConnectionPool cp = null;

    public CricLiveScoreHandler() {
        try {
            if (cp == null) {
                cp = new ConnectionPool("com.mysql.jdbc.Driver",
                        "jdbc:mysql://vas.rockvillegroup.com:3306/cricket", "root",
                        "iceland", 1, 1, true);
            }
        } catch (SQLException ex) {
            log.error("error getting connection parserMultiScore ", ex);
        }
    }

    public void run() {
        log.debug("*****CricLiveScoreHandler Started*****");
        Connection conn = null;
        try {
            conn = cp.getConnection();
            CallableStatement cs = conn.prepareCall("{ call get_smsevent(?, ?, ?, ?, ?, ?, ?) }");
            cs.registerOutParameter(1, java.sql.Types.INTEGER);
            cs.registerOutParameter(2, java.sql.Types.VARCHAR);
            cs.registerOutParameter(3, java.sql.Types.VARCHAR);
            cs.registerOutParameter(4, java.sql.Types.VARCHAR);
            cs.registerOutParameter(5, java.sql.Types.VARCHAR);
            cs.registerOutParameter(6, java.sql.Types.VARCHAR);
            cs.setString(7, "UFONE");
            cs.execute();
            int seqid = cs.getInt(1);
            String eventId = cs.getString(2);
            String eventType = cs.getString(3);
            String teamA = cs.getString(4);
            String teamB = cs.getString(5);
            String smsText = cs.getString(6);
            if (seqid > 0) {
            	DBProc dbp = DBProc.getInstance();
                dbp.updateCricEvent(teamA, teamB, smsText, eventId, eventType);
            }
        } catch(SQLException e) {
			log.error("", e);
        } finally {
        cp.free(conn);
        }
        log.debug ("*****CricLiveScoreHandler END*****");
    }

}
